import 'package:flutter_cupertino_datetime_picker/flutter_cupertino_datetime_picker.dart';
import 'package:imember/Util/Global.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:imember/Util/MyColor.dart';

import 'MyImage.dart';

class Button extends StatelessWidget {
  Button(this.text,
      {this.onTap, this.bgColor, this.fontColor, this.width, this.height, this.radius, this.fontSize, this.isBorderBg, this.margin});

  String text = "";
  void Function()? onTap;
  Color? bgColor;
  Color? fontColor;
  EdgeInsetsGeometry? margin;
  double? width;
  double? height;
  double? radius;
  double? fontSize;
  bool? isBorderBg = false;

  @override
  Widget build(BuildContext context) {
    isBorderBg = isBorderBg ?? false;
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: height ?? 50,
        width: width ?? 220,
        margin: margin,
        alignment: Alignment.center,
        decoration: isBorderBg!
            ? BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(radius ?? 8)),
                border: Border.all(width: 1.2, color: bgColor ?? MyColor.Green))
            : BoxDecoration(color: bgColor ?? MyColor.Green, borderRadius: BorderRadius.all(Radius.circular(radius ?? 8))),
        child: Text(text,
            style: TextStyle(
                color: fontColor != null ? fontColor : (isBorderBg! ? bgColor ?? MyColor.Green : Color(0xFFFFFFFF)),
                fontSize: fontSize ?? 15)),
      ),
    );
  }
}

class OrangeBtn extends StatelessWidget {
  String text = "";
  void Function()? onTap;
  EdgeInsetsGeometry? margin;
  double? radius;
  double? height;
  double? width;
  double? fontSize;

  OrangeBtn(this.text, {this.onTap, this.margin, this.fontSize, this.height, this.width, this.radius});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onTap,
        child: Container(
            height: height ?? 48,
            width: width ?? double.infinity,
            margin: margin,
            alignment: Alignment.center,
            decoration: BoxDecoration(color: MyColor.Orange, borderRadius: BorderRadius.all(Radius.circular(radius ?? 24))),
            child: Text(text, style: TextStyle(fontWeight: FontWeight.bold, color: Color(0xFFFFFFFF), fontSize: fontSize ?? 18))));
  }
}

class BlueBtn extends StatelessWidget {
  String text = "";
  void Function()? onTap;
  EdgeInsetsGeometry? margin;
  double? radius;
  double? height;
  double? width;
  double? fontSize;

  BlueBtn(this.text, {this.onTap, this.margin, this.fontSize, this.height, this.width, this.radius});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: height ?? 48,
        width: width ?? double.infinity,
        margin: margin,
        alignment: Alignment.center,
        decoration: BoxDecoration(color: MyColor.Blue, borderRadius: BorderRadius.all(Radius.circular(radius ?? 24))),
        child: Text(text, style: TextStyle(fontWeight: FontWeight.bold, color: Color(0xFFFFFFFF), fontSize: fontSize ?? 18)),
      ),
    );
  }
}

class IconBtn extends StatelessWidget {
  String text = "";
  String icon = "";
  void Function()? onTap;
  EdgeInsetsGeometry? margin;
  Color? bgColor;
  Color? fontColor;
  double? radius;
  double? height;
  double? width;

  IconBtn(this.text, this.icon, {this.onTap, this.margin, this.bgColor, this.fontColor, this.height, this.width, this.radius});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onTap,
        child: Container(
            height: height ?? 35,
            width: width ?? 225,
            decoration: Global.getBoxBg(radius ?? 18, bgColor ?? MyColor.Blue),
            child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
              LocalImage(icon, width: 20, padding: EdgeInsets.only(right: 16)),
              Text(text, style: TextStyle(fontSize: 15, color: fontColor ?? MyColor.White))
            ])));
  }
}

class TextBtn extends StatelessWidget {
  TextBtn(this.text, {this.onTap, this.height, this.alignment, this.margin, this.style});

  String text = "";
  void Function()? onTap;
  TextStyle? style;
  double? height;
  EdgeInsetsGeometry? margin;
  AlignmentGeometry? alignment;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        behavior: HitTestBehavior.opaque,
        child: Container(margin: margin, height: height, alignment: alignment ?? Alignment.center, child: Text(text, style: style)),
        onTap: onTap);
  }
}

class CalendarChooser extends StatelessWidget {
  String date;
  Function(DateTime dateTime, List<int> selectedIndex)? onConfirm;

  CalendarChooser(this.date, {this.onConfirm});

  chooseDate(BuildContext context) {
    FocusManager.instance.primaryFocus?.unfocus();
    DatePicker.showDatePicker(context,
        dateFormat: "yyyy年 MM月 dd日",
        pickerTheme: DateTimePickerTheme(confirm: Text("確認", style: TextStyle(fontSize: 14, color: MyColor.C58))),
        onConfirm: onConfirm);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () {
          chooseDate(context);
        },
        behavior: HitTestBehavior.translucent,
        child: Container(
            height: 36,
            width: 189,
            padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
            decoration:
                BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(18)), border: Border.all(width: 1, color: MyColor.C58)),
            child: Row(
              children: [Expanded(child: Text(date, style: TextStyle(fontSize: 17))), LocalImage("ic_calendar.png", width: 27)],
            )));
  }
}
